#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<map>
#include<set>
#include<bits/stdc++.h>
#include<unordered_set>
#define fi first
#define se second
#define SIZE(x) ((int)x.size())
#define out(x) cerr<<#x<<" = "<<(x)<<endl;
#define MP(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
#define VI vector<int>
#define VVI vector< vector<int> >
#define VD vector<double>
#define VVD vector<VD >
#define VC vector<char>
#define PI pair<int,int>
#define PL pair<ll,ll>
#define EPS 0.0000001


inline int lson(int x){return x<<1;}
inline int rson(int x){return (x<<1)|1;}

template<typename T>
inline void read(T &x){
        x=0;T f=1;char ch;
        do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
        do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

int n,m,blo;
int dat[200005];
int bl[200005];
int tag[200005];
int sum[200005];
void add(int a,int b){
	for(int i=a;bl[i]==bl[a]&&i<=b;i++){
		sum[bl[a]]+=(dat[i]^tag[bl[a]])?-1:1;
		dat[i]^=1;
	}
	if(bl[a]!=bl[b]){
		for(int i=b;bl[i]==bl[b];i--){
			sum[bl[b]]+=(dat[i]^tag[bl[b]])?-1:1;
			dat[i]^=1;
		}
	}
	for(int i=bl[a]+1;i<bl[b];i++){
		tag[i]^=1;
		sum[i]=blo-sum[i];
	}
}
int que(int a,int b){
	int res=0;
	for(int i=a;bl[i]==bl[a]&&i<=b;i++)if(dat[i]^tag[bl[i]])++res;
	if(bl[a]!=bl[b])for(int i=b;bl[i]==bl[b];i--)if(dat[i]^tag[bl[i]])++res;
	for(int i=bl[a]+1;i<bl[b];i++)res+=sum[i];
	return res;
}

//P3870
int main(){
    #ifdef BUG
    freopen("a.in","r",stdin);
    #endif
	read(n);read(m);
	memset(dat,0,sizeof dat);
	memset(tag,0,sizeof tag);
	memset(sum,0,sizeof sum);
	memset(bl,0,sizeof bl);
	blo=sqrt(n);
	for(int i=1;i<=n;i++)bl[i]=(i-1)/blo+1;
	int a,b,c;
	while(m--){
		read(c);read(a);read(b);
		if(!c)add(a,b);
		else printf("%d\n",que(a,b));
	}
}